<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/5/16
 * Time: 下午12:23
 */

class Product extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getProductList()
    {
        $post = $this->input->post();
        if (!isset($post['pagesize'])||!is_numeric($post['pagesize'])) $limit=10;
        else $limit = (int)$post['pagesize'];

        if (isset($post['pageno'])&&is_numeric($post['pageno'])) $offset = ((int)$post['pageno']-1)*$limit;
        else $offset = 0;

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getProductList($offset,$limit);

        $this->success($res);
    }

    public function getMedia()
    {
        $post = $this->input->post();
        if (!isset($post['gid'])||!is_numeric($post['gid'])||
            !isset($post['sls'])||empty($post['sls'])) $this->error();

        $this->load->model('kdtsalesman_model');
        $res = $this->kdtsalesman_model->getProductMedia($post['gid'],$post['sls']);

        $this->success($res);
    }

    public function redirectKdt($sls='',$gid=0)
    {
        if (empty($sls)||empty($gid)) die('params error');

        $this->load->model('kdtsalesman_model');
        $link = $this->kdtsalesman_model->getProductShortUrl($gid,$sls);
        if (!empty($link)) redirect($link);
        else die('link error');
    }
}